﻿
@{
    ViewBag.Title = "Index";
}


<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="pd-20">
    <div class="text-c">

        <input type="text" class="input-text" style="width:250px" id="txt_communityName" placeholder="输入小区名称">
        <button class="btn btn-success" id="btn_Search"><i class="Hui-iconfont">&#xe665;</i> 搜小区</button>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
            <a href="javascript:;" id="btn_AddHouse" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加房源</a>
            <a href="javascript:;" id="btn_Create" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 一键全部生成静态页</a>
        </span>

    </div>
    <table id="tb_HouseList" class="table table-border table-bordered table-bg">
        <thead>
            <tr>
                <th scope="col" colspan="9">房源列表</th>
            </tr>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="" value=""></th>

                <th width="200">区域</th>
                <th width="200">小区名</th>
                <th width="200">地段</th>
                <th width="200">租金</th>
                <th width="200">房型</th>
                <th width="200">装修</th>
                <th width="100">面积</th>
                <th width="200">操作</th>
            </tr>
        </thead>

    </table>
</div>

@section footScript
{

    <script src="~/Scripts/jquery.dataTables.min.js"></script>
    <script>


        function getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) { return pair[1]; }
            }
            return (false);
        }

        var params = {};

        $(function () {

            //接收当前的房源类型(从地址栏里面获取)

            var typeId = getQueryVariable("typeId");

            var table = $("#tb_HouseList").DataTable({
                pagingType: "full_numbers",//显示首页尾页
                processing: true, //显示加载中提示....
                ordering: false,//是否排序
                paging: true,//是否显示分页
                searching: false,//是否显示默认的搜索
                //使用对象数组，一定要配置columns，告诉 DataTables 每列对应的属性
                columns: [
                    { data: 'Id', },
                    { data: 'RegionName' },
                    { data: 'CommunityName' },
                    { data: 'Address' },
                    { data: 'MonthRent' },
                    { data: 'RoomTypeName' },
                    { data: 'DecorateStatusName' },
                    { data: 'Area' },
                    {
                        data: 'Id', render: function (data, type, full, callback) {
                            return (' <a title="编辑" href="javascript:;" data-id=' + data + '  class="ml-5 edit" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="上传" href="javascript:;"  data-id=' + data + '  class="ml-5 upload" style="text-decoration:none"><i class="Hui-iconfont">&#xe642;</i></a><a title="查看" href="javascript:;" data-id=' + data + '  class="ml-5 lookPic" style="text-decoration:none"><i class="Hui-iconfont">&#xe613;</i></a><a title="删除" href="javascript:;" data-id=' + data + ' class="ml-5 delete" style="text-decoration:none"> <i class="Hui-iconfont">&#xe6e2;</i></a>   ')
                        }
                    }

                ],
                createdRow: function (row, data, index) {
                    /* 设置表格中的内容居中 */
                    $('td', row).attr("class", "text-c");
                },
                //开启服务器模式
                serverSide: true,
                //使用ajax异步请求
                ajax: {
                    type: 'POST',
                    url: '/House/GetHouseList',
                    data: function (d) {
                        params.typeId = typeId;//房源类型
                        params.start = d.start;//开始的序号
                        params.length = d.length;//要取的数据的条数
                        return params;//自定义需要传递的参数。
                    }
                },
                columnDefs: [{
                    targets: 0,
                    render: function (data, type, row, meta) {
                        return '<input type="checkbox" value="' + row.Id + '" name="selectRoleIDs">';
                    }
                }
                    // { "orderable": false, "targets": 4 },
                ]
            });



            $("#btn_Search").click(function () {
                params.communityName = $("#txt_communityName").val();

                table.ajax.reload();
            });


            $("#btn_AddHouse").click(function () {

                layer_show("添加房源", "/House/Create", 950, 600);

            });


            //编辑房源
            $(".edit").livequery("click", function () {

                //获取要编辑的id
                var id = $(this).attr("data-id");

                //弹出编辑对话框
                layer_show("编辑房源", "/House/Edit?id=" + id, "950", "600");

            });

            //编辑房源
            $(".delete").livequery("click", function () {
                //获取当前点击 要删 的元素
                var _this = $(this);
                //弹出删除框
                layer.confirm("确定要删除吗?", { icon: 3, title: '提示' }, function () {
                    //获取要删除的该行的Id
                    var id = _this.attr("data-id");
                    //向服务器发送ajax请求
                    $.post("/House/Delete", { id: id }, function (data) {
                        if (data.State == 1) {
                            layer.msg(data.ErrorMessage);
                            location.reload();
                        } else {
                            layer.msg(data.ErrorMessage);
                        }
                    })

                });


     


            });

            //上传图片
            $(".upload").livequery("click", function () {

                //获取要房源的id
                var id = $(this).attr("data-id");

                //弹出上传图片对话框
                layer_show("上传图片", "/House/UploadPic?id=" + id, "800", "600");

            });


            //查看图片
            $(".lookPic").livequery("click", function () {

                //获取要房源的id
                var id = $(this).attr("data-id");

                //弹出查看图片对话框
                layer_show("上传图片", "/House/LookPic?id=" + id, "800", "500");

            });

            //生成静态页
            $("#btn_Create").click(function () {
                $.post("/House/CreateStaticPage", null, function (data) {
                    if (data.State == 1) {
                        //弹出提示信息
                        layer.msg(data.ErrorMessage, { icon: 1 });

                    }
                    else {
                        layer.msg(data.ErrorMessage, { icon: 5 });
                    }

                }, "json");

            });

        })

    </script>
}

